package com.bjsxt.userscenter.back.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bjsxt.userscenter.common.controller.BaseController;
import com.bjsxt.userscenter.common.util.ConstatFinalUtil;
import com.bjsxt.userscenter.common.util.PageInfoUtil;
import com.bjsxt.userscenter.users.pojo.AAdmins;
import com.bjsxt.userscenter.users.service.IUsersService;

/**
 * 管理员的操作Controller
 * 
 * @author wangshSxt
 *
 */
@Controller
@RequestMapping("/back/admins/")
public class AdminsBackController extends BaseController
{
	@Resource
	private IUsersService usersService;
	
	/**
	 * 登陆后的首页
	 * @return
	 */
	@RequestMapping("/main")
	public String main()
	{
		ConstatFinalUtil.LOGGER.info("---- main ----");
		return "/back/admins/main" ; 
	}
	
	/**
	 * 左侧菜单切换
	 * @return
	 */
	@RequestMapping("/leftMenu")
	public String leftMenu()
	{
		ConstatFinalUtil.LOGGER.info("---- leftMenu ----");
		return "/back/admins/leftMenu" ; 
	}
	
	/**
	 * 管理员列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/adminsList")
	public String adminsList(HttpServletRequest request)
	{
		ConstatFinalUtil.LOGGER.info("---- adminsList ----");
		/* 查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 分页 */
		PageInfoUtil pageInfoUtil = proccedPageInfo(request);
		
		/* 查询数据 */
		List<AAdmins> adminsList = this.usersService.findCondListAdminsService(pageInfoUtil, condMap);
		/* 将查询的数据放到四大作用域 */
		request.setAttribute("adminsList", adminsList);
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		return "/back/admins/adminsList" ; 
	}
	
	/**
	 * 退出
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/logout")
	public String logout(HttpServletRequest request,HttpSession session)
	{
		ConstatFinalUtil.LOGGER.info("---- logout ----");
		/* 将session中的信息删除 */
		session.removeAttribute("admins");
		session.removeAttribute("lastLoginTime");
		
		/* 操作Token */
		String token = request.getParameter("token");
		if(token == null)
		{
			token = "" ; 
		}
		if(!"".equalsIgnoreCase(token))
		{
			ConstatFinalUtil.TOKENS_MAP.remove(token);
		}
		
		this.info = ConstatFinalUtil.INFO_JSON.getString("8") ;
		/*request.setAttribute("info", info);
		return "/back/login" ; 
		*/
		session.setAttribute("info", info);
		return "redirect:/login.htm" ; 
	}
}
